﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace QQ.InterviewQuestions.Fibbonacci
{
    public class Fibbonacci
    {
        public int Execute(int n)
        {
           return f(n);
        }

        private int f(int n)
        {
            if (n==0 || n==1)
            {
                return 1;
            }
            else
            {
                return f(n - 1) + f(n - 2);
            }
        }

        public int ExecuteNonRecursive(int n)
        {
            int a = 0;
            int b = 1;
            int c = 0;

            for (int i = 0; i < n; i++)
            {
                c = a + b;
                a = b;
                b = c;
            }

            return c;
        }
    }
}
